package com.gz.spring.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class MyBeanPostProcessor implements BeanPostProcessor {
    //后置处理器

    /**
     * 在Bean的init方法前调用
     * @param bean
     * @param beanName
     * @return 程序员对传入的Bean 进行修改/处理(如果有需要的话)，返回
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization()...bean=" + bean+",beanName="+beanName);
        return bean;
    }

    /**
     * 在Bean的init方法后调用
     * @param bean
     * @param beanName
     * @return 程序员对传入的Bean 进行修改/处理(如果有需要的话)，返回
     * @throws BeansException
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization()...bean=" + bean+",beanName="+beanName);
        return bean;
    }

}
